package com.test.android.metro;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

import com.test.android.metro.model.MetroItem;
import com.test.android.metro.ui.MetroView;
import com.test.android.metro.ui.MetroView.OrientationType;

public class MetroUITwo extends Activity {

	private static final LayoutParams FILL_FILL = new LayoutParams(
			LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1.0f);

	private static final int PADDING = 10;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.metro_ui);

		MetroView view = (MetroView) findViewById(R.id.metro_ui);
		view.setBackgroundColor(Color.BLACK);

		view.setVisibleItems(4, 3);
		view.setOrientation(OrientationType.Vertical);

		view.addMetroItem(createLogo());
		view.addMetroItem(createMail());
		view.addMetroItem(createIE());
		view.addMetroItem(createTemperature());
		view.addMetroItem(createDate());
		view.addMetroItem(createPrograms());
		view.addMetroItem(createWallpaper());
		view.addMetroItem(createZune());
		view.addMetroItem(createBlank(3, 1));
		view.addMetroItem(createBlank(3, 2));
	}

	private MetroItem createLogo() {

		LinearLayout layout = new LinearLayout(this);
		layout.setBackgroundResource(R.color.windows_blue);
		layout.setGravity(Gravity.CENTER);
		layout.setPadding(PADDING, PADDING, PADDING, PADDING);

		ImageView logo = new ImageView(this);
		logo.setImageResource(R.drawable.logo);

		layout.addView(logo, FILL_FILL);

		return new MetroItem(layout, 0, 0);
	}

	private MetroItem createMail() {

		LinearLayout layout = new LinearLayout(this);
		layout.setBackgroundResource(R.color.windows_blue);
		layout.setGravity(Gravity.CENTER);
		layout.setPadding(PADDING, PADDING, PADDING, PADDING);
		layout.setOrientation(LinearLayout.VERTICAL);

		ImageView mail = new ImageView(this);
		mail.setImageResource(R.drawable.mail);

		layout.addView(mail, FILL_FILL);

		TextView tv = new TextView(this);
		tv.setText("3 new");
		tv.setGravity(Gravity.CENTER);
		tv.setTextColor(Color.WHITE);
		tv.setTextSize(20);

		layout.addView(tv, FILL_FILL);

		return new MetroItem(layout, 0, 1);
	}

	private MetroItem createIE() {

		LinearLayout layout = new LinearLayout(this);
		layout.setBackgroundResource(R.color.windows_blue);
		layout.setGravity(Gravity.CENTER);
		layout.setPadding(PADDING, PADDING, PADDING, PADDING);

		ImageView ie = new ImageView(this);
		ie.setImageResource(R.drawable.ie);

		layout.addView(ie, FILL_FILL);

		return new MetroItem(layout, 0, 2);
	}

	private MetroItem createTemperature() {

		LinearLayout layout = new LinearLayout(this);
		layout.setBackgroundResource(R.color.windows_blue);
		layout.setGravity(Gravity.CENTER);
		layout.setPadding(PADDING, PADDING, PADDING, PADDING);
		layout.setOrientation(LinearLayout.VERTICAL);

		TextView tv1 = new TextView(this);
		tv1.setText("11 °");
		tv1.setGravity(Gravity.CENTER);
		tv1.setTextColor(Color.WHITE);
		tv1.setTextSize(30);

		layout.addView(tv1, FILL_FILL);

		TextView tv2 = new TextView(this);
		tv2.setText("Light rain");
		tv2.setGravity(Gravity.CENTER);
		tv2.setTextColor(Color.WHITE);
		tv2.setTextSize(15);

		layout.addView(tv2, FILL_FILL);

		return new MetroItem(layout, 1, 0);
	}

	private MetroItem createDate() {

		LinearLayout layout = new LinearLayout(this);
		layout.setBackgroundResource(R.color.windows_blue);
		layout.setGravity(Gravity.CENTER);
		layout.setPadding(PADDING, PADDING, PADDING, PADDING);
		layout.setOrientation(LinearLayout.VERTICAL);

		TextView tv1 = new TextView(this);
		tv1.setText("March");
		tv1.setGravity(Gravity.CENTER);
		tv1.setTextColor(Color.WHITE);
		tv1.setTextSize(15);

		layout.addView(tv1, FILL_FILL);

		TextView tv2 = new TextView(this);
		tv2.setText("18");
		tv2.setGravity(Gravity.CENTER);
		tv2.setTextColor(Color.WHITE);
		tv2.setTextSize(30);

		layout.addView(tv2, FILL_FILL);

		return new MetroItem(layout, 1, 1);
	}

	private MetroItem createPrograms() {

		LinearLayout layout = new LinearLayout(this);
		layout.setBackgroundResource(R.color.windows_blue);
		layout.setGravity(Gravity.CENTER);
		layout.setPadding(PADDING, PADDING, PADDING, PADDING);
		layout.setOrientation(LinearLayout.VERTICAL);

		TextView tv1 = new TextView(this);
		tv1.setText("Programs");
		tv1.setGravity(Gravity.CENTER);
		tv1.setTextColor(Color.WHITE);
		tv1.setTextSize(15);

		layout.addView(tv1, FILL_FILL);

		TextView tv2 = new TextView(this);
		tv2.setText("xxx");
		tv2.setGravity(Gravity.CENTER);
		tv2.setTextColor(Color.WHITE);
		tv2.setTextSize(15);

		layout.addView(tv2, FILL_FILL);

		return new MetroItem(layout, 1, 2, 2, 1);
	}

	private MetroItem createWallpaper() {

		LinearLayout layout = new LinearLayout(this);
		layout.setBackgroundResource(R.color.windows_blue);
		layout.setGravity(Gravity.CENTER);

		ImageView ie = new ImageView(this);
		ie.setImageResource(R.drawable.wallpaper);
		ie.setScaleType(ScaleType.FIT_XY);

		layout.addView(ie, FILL_FILL);

		return new MetroItem(layout, 2, 1, 0, 2);
	}

	private MetroItem createZune() {

		LinearLayout layout = new LinearLayout(this);
		layout.setBackgroundResource(R.color.windows_blue);
		layout.setGravity(Gravity.CENTER);

		ImageView ie = new ImageView(this);
		ie.setImageResource(R.drawable.zune);

		layout.addView(ie, FILL_FILL);

		return new MetroItem(layout, 3, 0);
	}

	private MetroItem createBlank(int row, int col) {

		LinearLayout layout = new LinearLayout(this);
		layout.setBackgroundResource(R.color.windows_blue);

		return new MetroItem(layout, row, col);
	}
}
